package demo2;

import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.name.Named;

import javax.inject.Singleton;
import java.util.Map;
import java.util.Set;

@Singleton
public class Sample {

    @Inject
    @Named("complex")
    private HelloPrinterInterface printer;

    @Inject
    private Set<HelloPrinterInterface> printerSets;

    @Inject
    private Map<String, HelloPrinterInterface> printerMaps;

    public void hello() {
        printer.print();
    }

    public void helloSet() {
        for (HelloPrinterInterface printer : printerSets) {
            printer.print();
        }
    }

    public void helloMap() {
        for (String key : printerMaps.keySet()) {
            printerMaps.get(key).print();
        }
    }

    public static void main(String[] args) {
        Injector injector = Guice.createInjector(new SampleModule());
        Sample sample = injector.getInstance(Sample.class);
        sample.hello();
        sample.helloSet();
        sample.helloMap();
    }

}
